package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartOrderBean;

import java.util.ArrayList;
import java.util.List;

public class ProduceWorkPartDispatchInformationAdapter extends BaseAdapter{
    private Context context;
    private List<WorkPartOrderBean> workPartOrderList =new ArrayList();

    public ProduceWorkPartDispatchInformationAdapter(Context mContext ){
        this.context=mContext;
    }

    public void setData(List<WorkPartOrderBean> list) {
        this.workPartOrderList.clear();
        if (null != list) {
            this.workPartOrderList.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return workPartOrderList.size();
    }

    @Override
    public WorkPartOrderBean getItem(int position) {
        return workPartOrderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (null==convertView){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_produce_workpart_dispatch_information,null);
            holder.tv_dispatch_information=convertView.findViewById(R.id.tv_dispatch_information);
            holder.tv_dispatch_status=convertView.findViewById(R.id.tv_dispatch_status);

            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }


        WorkPartOrderBean workPartOrderBean = workPartOrderList.get(position);

        holder.tv_dispatch_information.setText(context.getResources().getString(R.string.dispatching_information));

        if (workPartOrderBean.getAssignReceiveStatus() == CommonEnum.ProduceOrderStatus.CREATED) {
            holder.tv_dispatch_status.setText("");
            holder.tv_dispatch_status.setTextColor(context.getResources().getColor(R.color.rgb_00000000));

        } else if (workPartOrderBean.getAssignReceiveStatus() == CommonEnum.ProduceOrderStatus.RETURNED) {
            holder.tv_dispatch_status.setText(context.getResources().getString(R.string.order_back));
            holder.tv_dispatch_status.setTextColor(context.getResources().getColor(R.color.color_b10e1a));

        } else if (workPartOrderBean.getAssignReceiveStatus() == CommonEnum.ProduceOrderStatus.RECEIVED) {
            holder.tv_dispatch_status.setText(context.getResources().getString(R.string.already_received));
            holder.tv_dispatch_status.setTextColor(context.getResources().getColor(R.color.color_2c9a2d));

        } else if (workPartOrderBean.getAssignReceiveStatus() == CommonEnum.ProduceOrderStatus.SEND) {
            holder.tv_dispatch_status.setText(context.getResources().getString(R.string.wait_receive));
            holder.tv_dispatch_status.setTextColor(context.getResources().getColor(R.color.rgb_FCD505));

        }else if (workPartOrderBean.getAssignReceiveStatus() == CommonEnum.ProduceOrderStatus.EDITED) {
            holder.tv_dispatch_status.setText(context.getResources().getString(R.string.wait_receive));
            holder.tv_dispatch_status.setTextColor(context.getResources().getColor(R.color.rgb_FCD505));

        }


        return convertView;
    }

    static class ViewHolder{
        TextView tv_dispatch_information;
        TextView tv_dispatch_status;
    }
}
